home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 031a / wb613_01.zip / WN_GBOOL.C < prev    next >
C/C++ Source or Header  |  1991-03-15  |  6KB  |  142 lines

  1. /*
  2. ** The Window BOSS's Data Clerk
  3. ** Copyright (c) 1988 - Philip A. Mongelluzzo
  4. ** All rights reserved.
  5. **
  6. ** wn_gbool - get logical (True/False) from window 
  7. **
  8. ** Copyright (c) 1988 - Philip A. Mongelluzzo
  9. ** All rights reserved.
  10. **
  11. */
  12.  
  13. #include "winboss.h"                    /* standard stuff */
  14.  
  15. /*
  16. ************
  17. * wn_gbool *
  18. ************
  19. */
  20.  
  21. /*
  22. ** wn_gbool(fun,frm,fld,wn,row,col,prmpt,atrib,fill,value,ubuff,hlpmsg,errmsg)
  23. **
  24. **    int        fun - fucntion code (SET || XEQ)
  25. **    (WIFORM)   frm - form pointer  (actual || NFRM)
  26. **    int        fld - field # in form (actual || NFLD)
  27. **    (WINDOWPTR) wn - window pointer
  28. **    int        row - row in window where data input begins
  29. **    int        col - col in window where data input begins
  30. **    (char *) prmpt - field promt (call with NSTR for none)
  31. **    unsigned atrib - field (not prompt) atributes 
  32. **    char      fill - field fill character
  33. **    (int *)  value - pointer to int for value (0=FALSE, 1=TRUE)
  34. **    (char *) ubuff - pointer to char array of 3 bytes for editing 
  35. **    (char *)hlpmsg - pointer to help message (call with NSTR for none)
  36. **    (char *)errmsg - pointer to err message (call with NSTR) for none)
  37. **
  38. ** RETURNS:
  39. **
  40. **    UBUFF with entered data via pointer.
  41. **
  42. **    NULL if error, else the non zero value returned from wn_input.
  43. **
  44. ** NOTES:
  45. **
  46. **  FUN -   fun can only be SET for form setup, or XEQ for immediate
  47. **          execution.  When called with SET, valid arguements for both
  48. **          "frm" and "fld" must be specfied.  frm is the field pointer
  49. **          returned from frmopn(), and fld is the field sequence number
  50. **          in the form for this field.  When called with XEQ frm must
  51. **          be NFRM and fld must NFLD.
  52. **
  53. **  UBUFF - Editing buffer.  Must be of sufficent size to hold the
  54. **          data as it is entered.  Typical value is the length
  55. **          of the mask + 2 bytes (strlen(mask)+2).
  56. **
  57. **          On entry, the first byte of ubuff should be 
  58. **          a null, otherwise wn_input assumes there is valid
  59. **          data there and will enter edit mode.  This can be 
  60. **          handy if there is a need for prefilled but editable
  61. **          fields.  In actual pratice, wn_input uses this
  62. **          buffer for both initial character data entry and
  63. **          subsequent editing.
  64. **
  65. **          On return, ubuff contains the actual data entered in
  66. **          character format with fill and mask characters as
  67. **          spaces (e.g. "T").
  68. **
  69. **  Calls wn_input to perform data entry.
  70. **
  71. **  User MUST enter T,F,Y, or N.
  72. **
  73. **  Data must satisfy validatin checks for function to return.
  74. **
  75. **  Calls wn_iemsg(errmsg) when vaildation fails.
  76. **
  77. */
  78.  
  79. /*
  80. ************
  81. * wn_gbool *
  82. ************
  83. */
  84.  
  85. wn_gbool(fun,frm,fld,wn,row,col,prmpt,atrib,fill,value,ubuff,hlpmsg,errmsg)
  86. int fun;                                /* SET or XEQ */
  87. WIFORM frm;                             /* form pointer or NFRM */
  88. int fld;                                /* field number or NFLD */
  89. WINDOWPTR wn;                           /* window to use */
  90. int row, col;                           /* position of input field */
  91. char *prmpt;                            /* prompt string */
  92. unsigned atrib;                         /* data entry atribute */
  93. char fill;                              /* fill char */
  94. int *value;                             /* the logical 0=FALSE, 1=TRUE */
  95. char *ubuff;                            /* returns "value" */
  96. char *hlpmsg, *errmsg;                  /* help & error messages */
  97. {
  98. char mask[3];                           /* Single char input */
  99. int rv;                                 /* return value */
  100.  
  101.   if(fun != SET && fun != XEQ)          /* saftey check */
  102.     return(NULL);
  103.  
  104.   if(fun == SET) {                      /* set up */
  105.     if(frm[fld]->pself != (char *)frm[fld])
  106.       wns_ierr("wn_gbool");             /* die if memory is mangled */
  107.     frm[fld]->wn = wn;                  /* set window */
  108.     frm[fld]->row = row;                /* set row */
  109.     frm[fld]->col = col;                /* set col */
  110.     frm[fld]->prmpt = prmpt;            /* set prompt */
  111.     frm[fld]->atrib = atrib;            /* set attribute */
  112.     frm[fld]->fill = fill;              /* set fill character */
  113.     frm[fld]->fcode = GBOOL;            /* function code */
  114.     frm[fld]->v1.vip = value;           /* value */
  115.     frm[fld]->v2.vcp = ubuff;           /* &ubuff */
  116.     frm[fld]->v3.vcp = hlpmsg;          /* &hlpmsg */
  117.     frm[fld]->v4.vcp = errmsg;          /* &errmsg */
  118.     return(TRUE);
  119.   }
  120.  
  121.   strcpy(mask,"u");                     /* set mask */
  122. begin:
  123.   if(!(rv=wn_input(wn,row,col,prmpt,mask,fill,atrib,ubuff,hlpmsg))) {
  124.     *ubuff= NUL;                        /* indicate error */
  125.     return(NULL);                       /* indicate error */
  126.   }
  127.   if(wni_frmflg) return(TRUE);          /* wn_frmget in progress */
  128.   if(wns_escape) return(rv);            /* escape pressed ?? */
  129.   if(*ubuff == 'T' || *ubuff == 'Y') {  /* T or Y = TRUE */
  130.     *value = 1;                         /* set user value */
  131.     return(rv);                         /* and return */
  132.   }
  133.   if(*ubuff == 'F' || *ubuff == 'N') {  /* F or N = FALSE */
  134.     *value = 0;                         /* set user value */
  135.     return(rv);                         /* and return */
  136.   }
  137.   wn_iemsg(errmsg);                     /* display error msg */
  138.   goto begin;                           /* till we get it right */
  139. }
  140.  
  141. /* End */
  142.